﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;//添加命名空间，可以使用OleDbConnection等对象
using System.Data;//添加命名空间，可以使用DataSet对象

public partial class admindtrstor_modifyPassword : System.Web.UI.Page
{
    public OleDbConnection myConnection;
    public static readonly string sConnectionString = System.Configuration.ConfigurationManager.AppSettings["SQLConnString"].ToString();
    protected void Page_Load(object sender, EventArgs e)
    {
        myConnection = new OleDbConnection(sConnectionString);
        myConnection.Open();
        if (Session["UserName"] == null && Session["UserNo"] == null)
            Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>" +
                "alert('登录超时（或未登录），请您重新登录！'); parent.location,href='../login.aspx'</script>", false);
    }
    protected void ButtonOk_Click(object sender, EventArgs e)
    {
        string psw;
        string mysql = "select * from managerTb where mNo='" + Session["UserNo"] + "' ";
        OleDbCommand mycmd = new OleDbCommand(mysql, myConnection);
        OleDbDataReader myReader = mycmd.ExecuteReader();
        if (myReader.Read())
        {
            psw = myReader[3].ToString();
            if (psw == TextBox1.Text.Trim())
            {
                if (TextBox2.Text.Trim() == TextBox3.Text.Trim())
                {
                    mysql = "update managerTb set mpass='" + TextBox2.Text.Trim() + "' where mNo='" + Session["UserNo"] + "' ";
                    mycmd = new OleDbCommand(mysql, myConnection);
                    mycmd.ExecuteNonQuery();
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>alert('密码修改成功！')</script>", false);
                    TextBox1.Text = "";
                    TextBox2.Text = "";
                    TextBox3.Text = "";
                    LabelError.Text = "";
                }
                else
                    LabelError.Text = "*您输入的两次新密码不一致，请重新输入！";
            }
            else
                LabelError.Text = "*您输入的旧密码不正确，请重新输入！";
        }
    }
    protected void ButtonSet_Click(object sender, EventArgs e)
    {
        TextBox1.Text = "";
        TextBox2.Text = "";
        TextBox3.Text = "";
        LabelError.Text = "";
    }
}